﻿using Styx.Common;
using Styx.CommonBot;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

namespace TuanHA_Monk
{
    public partial class Classname
    {
        #region Windwalker Rotation

        private Composite WindwalkerRotation()
        {
            return new PrioritySelector(
                new Action(delegate
                               {
                                   if (THSettings.Instance.SAutoTarget && !Me.Mounted &&
                                       Me.CurrentTarget != null && UnitAttack != null &&
                                       Me.CurrentTarget != UnitAttack &&
                                       UnitAttack.Combat && //Make sure don't aggro more
                                       (Me.CurrentTarget.Distance - 5f > UnitAttack.Distance ||
                                        !Me.CurrentTarget.InLineOfSight ||
                                        !Me.CurrentTarget.IsAlive ||
                                        !Me.CurrentTarget.Combat && Me.Combat))
                                   {
                                       Logging.Write(LogLevel.Diagnostic, "Select new Target");
                                       UnitAttack.Target();
                                   }

                                   //Hold dps on Dungeon or Raid
                                   if ((Me.CurrentMap.IsDungeon || Me.CurrentMap.IsRaid) &&
                                       Me.CurrentTarget != null &&
                                       !Me.CurrentTarget.Combat)
                                   {
                                       return RunStatus.Success;
                                   }

                                   return RunStatus.Failure;
                               }),
                //Starting the movement right here
                //But first, facing target
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) &&
                    IsEnemy(Me.CurrentTarget) &&
                    !Me.IsFacing(Me.CurrentTarget) &&
                    Me.CurrentTarget.InLineOfSight &&
                    !IsOverrideModeOn,
                    new Action(delegate
                                   {
                                       Me.CurrentTarget.Face();
                                       return RunStatus.Failure;
                                   })
                    ),
                new Decorator(
                    ret =>
                    Me.Mounted,
                    new Action(delegate { return RunStatus.Success; })
                    ),
                //DPS Rotation Here
                //Hold DPS while channelling FoF, Spinning Crane Kick
                new Decorator(
                    ret =>
                    Me.IsCasting && (Me.ChanneledCastingSpellId == 113656 || Me.ChanneledCastingSpellId == 101546),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Fortifying Brew pls");
                                       return RunStatus.Success;
                                   })
                    ),
                //[Zen Meditation]
                new Decorator(
                    ret =>
                    THSettings.Instance.SFSK &&
                    !Me.Mounted &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) && !Me.IsSwimming &&
                    !CastingorGCDL() && Me.CurrentTarget.Distance > 13 &&
                    Me.CurrentTarget.Distance < 40 &&
                    Me.CurrentTarget.InLineOfSight &&
                    HasGlyph.Contains("Glyph of Flying Serpent Kick") &&
                    SpellManager.HasSpell("Flying Serpent Kick") &&
                    SpellManager.Spells["Flying Serpent Kick"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Flying Serpent Kick pls");
                                       if (!Me.IsSafelyFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                           return RunStatus.Running;
                                       }
                                       CastSpell("Flying Serpent Kick", Me.CurrentTarget);
                                       return RunStatus.Success;
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SRoll &&
                    !Me.Mounted &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) && Me.GetAuraById(119085) == null && //119085 Momentum
                    !CastingorGCDL() &&
                    //Need distance > 10 or you will roll out of melee range
                    Me.CurrentTarget.Distance > 15 &&
                    Me.CurrentTarget.Distance < 40 &&
                    Me.CurrentTarget.InLineOfSight &&
                    SpellManager.HasSpell("Roll") &&
                    SpellManager.Spells["Roll"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Roll pls");
                                       if (!Me.IsSafelyFacing(UnitAttack))
                                       {
                                           UnitAttack.Face();
                                           return RunStatus.Running;
                                       }
                                       CastSpell("Roll", Me.CurrentTarget);
                                       return RunStatus.Failure;
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SSpearHandStrike &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentTarget.IsCasting && Me.CurrentTarget.CanInterruptCurrentSpellCast &&
                    Me.CurrentEnergy >= 30 &&
                    SpellManager.HasSpell("Spear Hand Strike") &&
                    SpellManager.Spells["Spear Hand Strike"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Spear Hand Strike pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Spear Hand Strike", Me.CurrentTarget);
                                       return RunStatus.Failure;
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SProvoke &&
                    !Me.Mounted &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    !Me.IsInInstance &&
                    !CastingorGCDL() && Me.CurrentTarget.Distance > 10 &&
                    Me.CurrentTarget.Distance < 40 &&
                    Me.CurrentTarget.InLineOfSight &&
                    //Only provoke target that have no target or not targeting me
                    !Me.CurrentTarget.IsTargetingMeOrPet &&
                    SpellManager.HasSpell("Provoke") &&
                    //Only provoke when not Clashing, rolling or roll on cooldown
                    LastCastSpell != "Flying Serpent Kick" &&
                    LastCastSpell != "Roll" &&
                    //Don't use 2 OFF GCD spell together
                    SpellManager.Spells["Provoke"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Provoke pls");
                                       CastSpell("Provoke", Me.CurrentTarget);
                                       return RunStatus.Failure;
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.HasAura("Tigereye Brew") &&
                    Me.GetAuraByName("Tigereye Brew").StackCount > 9 &&
                    Me.CurrentTarget.CurrentHealth > Me.CurrentHealth - (Me.CurrentHealth*0.2) &&
                    SpellManager.HasSpell("Tigereye Brew") &&
                    SpellManager.Spells["Tigereye Brew"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Tigereye Brew pls");
                                       CastSpell("Tigereye Brew", Me);
                                       return RunStatus.Failure;
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentEnergy <= 30 && Me.CurrentChi < 2 &&
                    Me.HasAura("Tiger Power") &&
                    Me.GetAuraByName("Tiger Power").TimeLeft.TotalSeconds > 5 &&
                    Me.GetAuraByName("Tiger Power").StackCount > 2 &&
                    SpellManager.HasSpell("Energizing Brew") &&
                    SpellManager.Spells["Energizing Brew"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Energizing Brew pls");
                                       CastSpell("Energizing Brew", Me);
                                       return RunStatus.Failure;
                                   })
                    ),
                //Invoke Xuen, the White Tiger
                new Decorator(
                    ret =>
                    THSettings.Instance.SXuen &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.Combat &&
                    Me.CurrentTarget.CurrentHealth > Me.CurrentHealth - (Me.CurrentHealth*0.2) &&
                    (Me.CurrentTarget.IsPlayer || Me.CurrentTarget.MaxHealth > Me.MaxHealth*5) &&
                    SpellManager.HasSpell("Invoke Xuen, the White Tiger") &&
                    SpellManager.Spells["Invoke Xuen, the White Tiger"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       CastSpell("Invoke Xuen, the White Tiger", Me.CurrentTarget);
                                       return RunStatus.Failure;
                                   })),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    !CastingorGCDL() &&
                    Me.Combat && Me.HealthPercent < THSettings.Instance.SUrgentHeal &&
                    (!Me.HasAura("Fortifying Brew") ||
                     Me.HealthPercent < THSettings.Instance.SUrgentHeal - 20) &&
                    Me.CurrentChi >= 2 &&
                    Me.CurrentTarget.CurrentHealth > Me.CurrentHealth - (Me.CurrentHealth*0.2) &&
                    SpellManager.HasSpell("Touch of Karma") &&
                    SpellManager.Spells["Touch of Karma"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Touch of Karma pls");
                                       CastSpell("Touch of Karma", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.STouchofDeath &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    (Me.CurrentChi >= 3 || HasGlyph.Contains("Glyph of Touch of Death")) &&
                    Me.CurrentTarget.CurrentHealth > Me.CurrentHealth - (Me.CurrentHealth*0.2) &&
                    SpellManager.HasSpell("Touch of Death") && Me.HasAura("Death Note"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Touch of Death pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Touch of Death", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SSpearHandStrike &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.CurrentTarget.IsWithinMeleeRange &&
                    //use to interrupt or survive
                    (Me.CurrentTarget.IsCasting && LastCastSpell != "Spear Hand Strike" ||
                     Me.HealthPercent < THSettings.Instance.SUrgentHeal) &&
                    Me.CurrentEnergy >= 30 &&
                    HasTalent.Contains("Leg Sweep") &&
                    SpellManager.Spells["Leg Sweep"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate { CastSpell("Leg Sweep", Me.CurrentTarget); })
                    ),
                new Decorator(
                    ret =>
                    !CastingorGCDL() &&
                    Me.Combat &&
                    Me.HealthPercent < THSettings.Instance.SPriorityHeal &&
                    HasTalent.Contains("Zen Sphere") && Me.CurrentChi >= 2 &&
                    SpellManager.Spells["Zen Sphere"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Zen Sphere pls");
                                       CastSpell("Zen Sphere", Me);
                                   })
                    ),
                //Heal > AOE DPS, dead = no dps
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.Distance < 40 &&
                    Me.CurrentTarget.InLineOfSpellSight &&
                    Me.HealthPercent < THSettings.Instance.SPriorityHeal &&
                    HasTalent.Contains("Chi Wave") && Me.CurrentChi >= 2 &&
                    SpellManager.Spells["Chi Wave"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Chi Wave pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Chi Wave", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentEnergy >= 15 &&
                    (Me.CurrentTarget.IsPlayer || Me.CurrentTarget.Fleeing) &&
                    Me.CurrentTarget.MovementInfo.RunSpeed > 3.5 &&
                    SpellManager.HasSpell("Disable"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Disable pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Disable", Me.CurrentTarget);
                                   })
                    ),
                //Survie > AOE DPS, dead = no dps
                new Decorator(
                    ret =>
                    //Only Expel Harm outside instance, it a lose dps
                    Me.IsInInstance &&
                    LastCastSpell != "Expel Harm" &&
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.HealthPercent < 80 &&
                    Me.CurrentEnergy >= 40 && //Fix, Thank Abroseh
                    //Because it generate 2 chi 
                    Me.CurrentChi <= Me.MaxChi - 2 &&
                    SpellManager.HasSpell("Expel Harm") &&
                    SpellManager.Spells["Expel Harm"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Expel Harm");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Expel Harm", Me);
                                   })
                    ),
                //AOE Rising Sun Kick
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentChi >= Me.MaxChi - 2 &&
                    CountEneyNeary(Me, 8) >= 3 &&
                    SpellManager.HasSpell("Rising Sun Kick") &&
                    SpellManager.Spells["Rising Sun Kick"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Rising Sun Kick pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Rising Sun Kick", Me.CurrentTarget);
                                   })
                    ),
                //AOE Spinning Crane Kick
                new Decorator(
                    ret =>
                    !CastingorGCDL() &&
                    Me.CurrentEnergy >= 40 &&
                    //Because it generate 1 chi if hit 3 target
                    Me.CurrentChi <= Me.MaxChi - 1 &&
                    (CountEneyNeary(Me, 8) >= THSettings.Instance.SSpinningCraneKick + 4 ||
                     CountEneyNeary(Me, 8) >= THSettings.Instance.SSpinningCraneKick &&
                     Me.HasAura("Tiger Power") &&
                     Me.GetAuraByName("Tiger Power").TimeLeft.TotalSeconds > 5 &&
                     Me.GetAuraByName("Tiger Power").StackCount > 2) &&
                    SpellManager.HasSpell("Spinning Crane Kick"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Spinning Crane Kick pls");
                                       CastSpell("Spinning Crane Kick", Me);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    (Me.CurrentChi <= Me.MaxChi - 2 || !SpellManager.HasSpell("Tiger Palm")) &&
                    //!SpellManager.HasSpell("Tiger Palm") for low level
                    Me.EnergyPercent > 40, // &&
                    //Well everyone suppose to have Jab anyway
                    //SpellManager.HasSpell("Jab"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Jab pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Jab", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    //!SpellManager.HasSpell("Blackout Kick") for low level
                    (!SpellManager.HasSpell("Blackout Kick") ||
                     !Me.HasAura("Tiger Power") ||
                     Me.HasAura("Tiger Power") &&
                     Me.GetAuraByName("Tiger Power").StackCount < 3 ||
                     Me.HasAura("Tiger Power") &&
                     Me.GetAuraByName("Tiger Power").TimeLeft.TotalSeconds < 10 &&
                     Me.CurrentTarget.CurrentHealth < Me.MaxHealth/4 ||
                     Me.HasAura("Tiger Power") &&
                     Me.GetAuraByName("Tiger Power").TimeLeft.TotalSeconds < 5) &&
                    (Me.CurrentChi >= 1 || Me.HasAura("Combo Breaker: Tiger Palm")) &&
                    SpellManager.HasSpell("Tiger Palm"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Tiger Palm pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Tiger Palm", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentChi >= Me.MaxChi - 2 &&
                    SpellManager.HasSpell("Rising Sun Kick") &&
                    SpellManager.Spells["Rising Sun Kick"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Rising Sun Kick pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Rising Sun Kick", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentTarget.CurrentHealth > Me.MaxHealth/2 &&
                    !Me.IsMoving && (!Me.CurrentTarget.IsMoving || Me.CurrentTarget.IsPlayer) &&
                    (!Me.HasAura("Energizing Brew") && Me.CurrentEnergy <= 40 ||
                     Me.CurrentEnergy <= 20) &&
                    Me.HasAura("Tiger Power") &&
                    Me.GetAuraByName("Tiger Power").TimeLeft.TotalSeconds > 5 &&
                    Me.GetAuraByName("Tiger Power").StackCount > 2 &&
                    (CountEneyNeary(Me, 8) < 3 || !SpellManager.HasSpell("Spinning Crane Kick")) &&
                    SpellManager.HasSpell("Fists of Fury") &&
                    SpellManager.Spells["Fists of Fury"].CooldownTimeLeft.TotalMilliseconds <= MyLatency,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Fists of Fury pls");
                                       ConstantFace(Me.CurrentTarget);
                                       CastSpell("Fists of Fury", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentChi >= Me.MaxChi - 1 &&
                    SpellManager.HasSpell("Blackout Kick"),
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Blackout Kick pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Blackout Kick", Me.CurrentTarget);
                                   })
                    ),
                //Jap if energy Cap
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) && IsEnemy(Me.CurrentTarget) &&
                    Me.IsFacing(Me.CurrentTarget) &&
                    !CastingorGCDL() && Me.CurrentTarget.IsWithinMeleeRange &&
                    Me.CurrentEnergy > 90,
                    new Action(delegate
                                   {
                                       //Logging.Write(LogLevel.Diagnostic, "Call Jab pls");
                                       if (!Me.IsFacing(Me.CurrentTarget))
                                       {
                                           Me.CurrentTarget.Face();
                                       }
                                       CastSpell("Jab", Me.CurrentTarget);
                                   })
                    ),
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    LastCastSpell != "Legacy of the Emperor" &&
                    !Me.Mounted &&
                    Me.CurrentEnergy >= 95 &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Legacy of the Emperor") &&
                    !Me.HasAura("Blessing of Kings") &&
                    !Me.HasAura("Mark of the Wild") &&
                    //!Me.HasAura("Embrace of the Shale Spider") &&
                    Me.EnergyPercent > 50 &&
                    SpellManager.HasSpell("Legacy of the Emperor"),
                    new Action(delegate { CastSpell("Legacy of the Emperor", Me); })
                    ),
                // [Legacy of the White Tiger]
                new Decorator(
                    ret =>
                    THSettings.Instance.SBuff &&
                    LastCastSpell != "Legacy of the White Tiger" &&
                    !Me.Mounted &&
                    Me.CurrentEnergy >= 95 &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Legacy of the White Tiger") &&
                    //!Me.HasAura("Leader of the Pack") &&
                    !Me.HasAura("Arcane Brilliance") &&
                    !Me.HasAura("Dalaran Brilliance") &&
                    //!Me.HasAura("Furious Howl") &&
                    //!Me.HasAura("Terrifying Roar") &&
                    //!Me.HasAura("Fearless Roar") &&
                    //!Me.HasAura("Still Water") &&
                    Me.EnergyPercent > 50 &&
                    SpellManager.HasSpell("Legacy of the White Tiger"),
                    new Action(delegate { CastSpell("Legacy of the White Tiger", Me); })
                    ),
                new Decorator(
                    ret =>
                    !Me.Mounted &&
                    !CastingorGCDL() &&
                    !Me.HasAura("Stance of the Fierce Tiger"),
                    new Action(delegate { CastSpell("Stance of the Fierce Tiger", Me); })
                    ),
                //Make sure facing problem gone forever
                new Decorator(
                    ret =>
                    ValidUnit(Me.CurrentTarget) &&
                    IsEnemy(Me.CurrentTarget) &&
                    !Me.IsFacing(Me.CurrentTarget) &&
                    Me.CurrentTarget.InLineOfSight &&
                    !IsOverrideModeOn,
                    new Action(delegate
                                   {
                                       Me.CurrentTarget.Face();
                                       return RunStatus.Failure;
                                   })
                    )
                );
        }

        #endregion
    }
}